package com.futureCloudMOM.core.service.impl;

import com.futureCloudMOM.core.base.service.impl.BaseServiceImpl;
import com.futureCloudMOM.core.domain.WmsInvoiceSub;
import com.futureCloudMOM.core.mapper.WmsInvoiceMainMapper;
import com.futureCloudMOM.core.service.WmsInvoiceSubService;
import com.futureCloudMOM.core.mapper.WmsInvoiceSubMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
* 【WMS_InvoiceSub】的数据库操作Service实现
*
* @author Administrator
* @since 2023-06-07 09:14:44
*/
@AllArgsConstructor
@Service
public class WmsInvoiceSubServiceImpl extends BaseServiceImpl<WmsInvoiceSubMapper, WmsInvoiceSub> implements WmsInvoiceSubService{

    // 业务订单主表
    private final WmsInvoiceMainMapper mainMapper;

    // 业务订单子表
    private final WmsInvoiceSubMapper subMapper;

    @Override
    public void deductQty(Long InvoiceMainId, Long InvoiceSubId, BigDecimal qty) {
        // 根据主表ID更新主表数据 待定


        // 根据子表ID 更新子表数量
        WmsInvoiceSub wmsInvoiceSub = subMapper.selectById(InvoiceSubId);
        // 已关联数量增加
        wmsInvoiceSub.setRelationQty(wmsInvoiceSub.getRelationQty().add(qty));
        // 未关联数量扣减
        wmsInvoiceSub.setNotRelationQty(wmsInvoiceSub.getNotRelationQty().subtract(qty));
        subMapper.updateById(wmsInvoiceSub);
    }

    @Override
    public void backQty(Long InvoiceMainId, Long InvoiceSubId, BigDecimal qty) {
        // 根据主表ID更新主表数据 待定


        // 根据子表ID 更新子表数量
        WmsInvoiceSub wmsInvoiceSub = subMapper.selectById(InvoiceSubId);
        // 已关联数量扣减
        wmsInvoiceSub.setRelationQty(wmsInvoiceSub.getRelationQty().subtract(qty));
        // 未关联数量增加
        wmsInvoiceSub.setNotRelationQty(wmsInvoiceSub.getNotRelationQty().add(qty));
        subMapper.updateById(wmsInvoiceSub);
    }


}
